﻿using System;
using System.Linq;
using System.Collections.Generic;
using System.Reflection;
using System.Diagnostics;

using iPhoneUI.Shell;

namespace iPhoneUI
{
    public static class ObjectExtensions
    {
        public static void SetProperties(this object o, IEnumerable<PropertyConfig> properties)
        {
            Debug.Assert(properties != null);

            foreach (PropertyConfig property in properties)
                SetProperty(o, property);
        }

        public static void SetProperty(this object o, PropertyConfig property)
        {
            Debug.Assert(o != null);

            PropertyInfo p = o.GetType().GetProperty(property.Name);
            Debug.Assert(p != null);
            Debug.Assert(p.CanWrite);

            p.SetValue(o, property.GetValue(p.PropertyType), null);
        }
    }
}
